package com.xand.bt.terminal.ui.logger;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;

import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.TableColumn;

import com.xand.bt.terminal.ui.UIConst;

public class LoggerTableDisplay {

	private JTable jTable;
	
	private LoggerTableModel model;
	
	private JPanel jPanel;
	
	private LoggerTableController controller;
	
	public LoggerTableDisplay() {
		
		this.model = new LoggerTableModel();
		this.controller = new LoggerTableController(this.model);
		
		this.jTable = new JTable(this.model);
		this.jTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
		this.jTable.setFocusable(false);
		this.jTable.setCellSelectionEnabled(false);
		this.jTable.setBorder(UIConst.EMPTY_BORDER);
		this.jTable.getTableHeader().setReorderingAllowed(false);
		
		this.adjustColumnWidth();
		
		JScrollPane scrollPane = new JScrollPane(this.jTable);
		scrollPane.setBorder(UIConst.EMPTY_BORDER);
		
		this.jPanel = new JPanel(new BorderLayout());
		this.jPanel.add(scrollPane);
		this.jPanel.setPreferredSize(UIConst.LOGGER_PANEL_SIZE);
		this.jPanel.setBorder(UIConst.LOGGER_PANEL_BORDER);
	}
	
	public JPanel getPanel() {
		return this.jPanel;
	}
	
	public JTable getTable() {
		return this.jTable;
	}
	
	public LoggerTableModel getModel() {
		return this.model;
	}
	
	public LoggerTableController getController() {
		return this.controller;
	}
	
	private void adjustColumnWidth() {
		TableColumn timestampColumn = this.jTable.getColumnModel().getColumn(0);
		TableColumn traceColumn = this.jTable.getColumnModel().getColumn(1);
		
		timestampColumn.setPreferredWidth(60);
		
		traceColumn.setPreferredWidth(830);
	}
	
}
